<template>
  <div class="app-container book">
    <span class="title">报纸推荐</span>
    <div class="content">
      <div class="block" v-for="(item,index) in classList" :key="index" @click="goToInfo(item)">
        <div class="item">
          <img class="content-cover" :src="'http://c61.cnki.net/ccnd/'+item.max_file_name.slice(0, 4) +'.jpg'" alt="">
          <span class="name" v-html="item.paper_name"></span>
          <span class="time" v-html="FromatPushTime(item.max_date)"></span>
        </div>
      </div>
    </div>
    <div class="pagination">
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page.sync="currentPage" :page-size="pageSize" layout="prev, pager, next, jumper" :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
  import {GetNewList} from "../../api/Api";

  export default {
  data() {
    return {
      classList:[],
      classTypeList:[],
      total:0,
      pageSize:24,
      currentPage:Number(this.$route.query.currentPage)||1,
      type_name:null,
      loading:true
    };
  },
  components: {},
  created(){
    GetNewList(4,'',this.currentPage,this.pageSize)
      .then(result=>{
        this.loading = false
        this.total = result.total
        this.currentPage = Number(this.$route.query.currentPage)||1
        return this.classList = result.data
      })
  },
  methods: {
    goToInfo(item) {
      this.$router.push("/newspaper/info?max_file_name="+item.max_file_name.slice(0,4)+"&resourceType=4&value="+item.paper_name);
    },
    handleSizeChange(val) {
      this.$router.push(this.$route.path+'?currentPage='+this.currentPage)
    },
    handleCurrentChange(val) {
      this.$router.push(this.$route.path+'?currentPage='+this.currentPage)
    }
  },
    watch:{
      '$route'(){
        console.log(1)
        this.currentPage = Number(this.$route.query.currentPage)||1
        GetNewList(4,'',this.currentPage,this.pageSize)
          .then(result=>{
            this.currentPage = Number(this.$route.query.currentPage)||1
            return this.classList = result.data
          })
      }
    }
};
</script>
<style lang="less" scoped>
.book {
  padding: 0px 20px 20px 20px;
  margin-top: 20px;
  border-radius: 10px;
  background: #fff;
  .title {
    font-size: 26px;
    display: block;
    padding: 20px 0px;
    border-bottom: 1px solid #c1c1c1;
  }
  .content {
    display: flex;
    flex-wrap: wrap;
    width: 100%;
    border-bottom: 1px solid #eaeaea;
    margin-bottom: 30px;
    .block {
      width: 226px;
      margin-top: 20px;
      padding-bottom: 24px;
      border-bottom: 1px solid #eaeaea;
      margin-bottom: -1px;
      cursor: pointer;
      .item {
        display: flex;
        flex-direction: column;
        .content-cover {
          width: 226px;
          height: 86px;
          border-radius: 10px;
          box-shadow: 0 2px 10px rgba(0,0,0,0.4);
        }
        .name {
          font-size: 18px;
          margin-top: 10px;
        }
        .time {
          font-size: 14px;
          color: #a1a1a1;
          margin-top: 5px;
        }
      }
    }
    .block:not(:nth-child(4n + 1)) {
      padding-left: 85px;
    }
  }
}
</style>


